<?php

require_once (dirname(__FILE__).'/../../course/moodleform_mod.php');
require_once(dirname(__FILE__).'/module_resourcepage.php');
if(file_exists($CFG->dirroot.'/local/references/apibib_apibib_lib.php')){
    require_once($CFG->dirroot.'/local/references/apibib_apibib_lib.php');
}

class mod_resourcepage_mod_form extends moodleform_mod {

	function definition() {

        // Require course id
        // Would be better if course object was always custom data for modules
        global $COURSE;

		$mform    =& $this->_form;
//-------------------------------------------------------------------------------
        // Add General box
        $mform->addElement('header', 'general', get_string('general', 'form'));

        $mform->addElement('text', 'name', get_string('field_name', 'resourcepage'));
        $mform->setType('name', PARAM_TEXT);
        $mform->addRule('name', null, 'required', null, 'client');
//-------------------------------------------------------------------------------
        // Add standard elements such as Visible
        $features = new stdClass();
        $features->groups = false;
        $this->standard_coursemodule_elements($features);
//-------------------------------------------------------------------------------
        // Add Optional box
        $mform->addElement('header', 'optional', get_string('optional', 'form'));

        // Add shared no/yes dropdown
        $mform->addElement('selectyesno', 'shared', get_string('field_shared', 'resourcepage'));
        $mform->setHelpButton('shared', array('shared', get_string('help_shared', 'resourcepage'), 'resourcepage'));

        // Add public feed no/yes dropdown
        $mform->addElement('selectyesno', 'publicfeed', get_string('field_publicfeed', 'resourcepage'));
        $mform->setHelpButton('publicfeed', array('allowfeed', get_string('help_allowfeed', 'resourcepage'), 'resourcepage'));

        //Get available styles for formatting references.
        $styleoptarray=array();
        if(property_exists('apibib','referencestyles')){
            
            for($a=0;$a<count(apibib::$referencestyles);$a++){
                $styleoptarray[]=apibib::$referencestyles[$a]['string'];
            }
        }
        if(count($styleoptarray)>0){
            //Reference style to use for reference item titles
            $select = &$mform->addElement('select', 'refstyle', get_string('reference_stylechoice','resourcepage'), $styleoptarray);
            $select->setMultiple(false);
        }
        
        //allow refrences to be displayed
        $mform->addElement('selectyesno', 'exportrefs', get_string('reference_refexportchoice', 'resourcepage'));
        
//-------------------------------------------------------------------------------
        // Add Save Changes and Cancel buttons
        $this->add_action_buttons(false);
	}
}
?>